package com.zhanqiao.Dao;

import com.zhanqiao.Utils.GetDataSourceUtil;
import com.zhanqiao.domain.ArticleBean;
import com.zhanqiao.domain.ProductBean;
import org.apache.commons.dbutils.QueryRunner;
import javax.sql.DataSource;
import java.sql.SQLException;
import java.util.Date;
import java.util.List;

public class OnSaleDao implements ArticleDao {
    @Override
    public int insertArticle(ProductBean productBean, String tag) {
        DataSource ds = GetDataSourceUtil.getDataSource();
        QueryRunner queryRunner = new QueryRunner(ds);
        Integer statu;
        if (tag.equals("0")) {
            statu = new Integer(1);

        } else {
            statu = new Integer(2);
        }
        Object[] parm = {productBean.getPname(), productBean.getPgetprice(), productBean.getPsaleprice(), productBean.getPduetime(), productBean.getPcount(), statu};
        String sql ="insert into product(pname,pgetprice,psaleprice,pduetime,pcount,pstatus) value(?,?,?,?,?,?)";
        try {
            int res = queryRunner.update(sql, parm);
            return res;
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return 0;
    }

    @Override
    public int deleteProduct(int pid) {
        return 0;
    }

    @Override
    public List<ArticleBean> selectAll() {
        return null;
    }

    @Override
    public int updateProduct(Integer pid, String pname, Integer psaleprice, Integer pcount) throws SQLException {
        return 0;
    }


}
